﻿using System;

using LAIR.Collections.Generic;
using LAIR.ResourceAPIs.WordNet;

namespace SearchingWebServices
{
    public static class WordNet
    {
        private static readonly WordNetEngine WordNetEngine = new WordNetEngine("dict", true);
        private static readonly WordNetSimilarityModel SemanticSimilarityModel = new WordNetSimilarityModel(WordNetEngine);

        public static SynSet GetMostCommonSynSet(string word)
        {
            return WordNetEngine.GetMostCommonSynSet(word, WordNetEngine.POS.Noun);
        }

        public static Set<SynSet> GetAllSynSets(string word)
        {
            return WordNetEngine.GetSynSets(word, WordNetEngine.POS.Noun);
        }

        public static float ComputeSimilarity(SynSet set1, SynSet set2)
        {
            try
            {
                return SemanticSimilarityModel.GetSimilarity(set1, set2, WordNetSimilarityModel.Strategy.WuPalmer1994Average, WordNetEngine.SynSetRelation.Hypernym);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return 0F;
            }
        }
    }
}
